<!--
 * @Description: 百世物流单
 * 
 * @Author: Edan<Edan>
 * @Date: 2024-08-15 16:35:19
 * @FilePath: /yuxiuproweb/src/views/material/returnRecord/mods/add.vue
-->

<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="title"
    :visible.sync="shows"
    width="90vw"
    top="2vh !important"
    append-to-body
  >
    <selInventory
      ref="selInventory"
      :multi="1"
      :showSearch="true"
      :tableHeight="'60vh'"
      :tableSize="'mini'"
      :repositoryName="'主材仓库'"
      :hideColumn="[]"
    >
      <template slot="btnLeft">
        <!-- v-if="!form.process" -->
        <div style="margin-left: 10px"></div>
      </template>
    </selInventory>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 认</el-button>
      <el-button @click="shows = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import selInventory from "@/views/material/inventory/mods/selectP.vue";
import commonMix from "@/utils/mixins/common";
import request from "@/utils/request";
export default {
  components: { selInventory },
  mixins: [commonMix],
  props: {
    show: Boolean,
    type: {
      type: String,
      default: "add",
    },
    data: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      // 表单参数
      loading: false,
      row_Val: "",
    };
  },
  computed: {
    title() {
      return {
        add: "生成盘点单",
        edit: "生成盘点单",
      }[this.type];
    },
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
      },
    },
  },
  async mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.$nextTick(() => {
        this.$refs.selInventory.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      const selListVal = this.$refs.selInventory.$refs.selectVal.selection;
      console.log("提交", selListVal);
      if (!selListVal.length) {
        this.$message.error("请选择要盘点的型号！！");
        return;
      }
      request({
        url: "/md/check",
        method: "post",
        data: selListVal,
      }).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess(res.msg || "保存成功");
          this.shows = false;
          this.$emit("update");
        } else {
          this.$message.error(res.msg || "操作失败");
        }
      });
    },
  },
  filters: {
    dateFormat(dataStr) {
      if (!dataStr) {
        return;
      }
      var dt = new Date(dataStr);
      var y = dt.getFullYear();
      var m = (dt.getMonth() + 1).toString().padStart(2, "0");
      var d = dt.getDate().toString().padStart(2, "0");
      var hh = dt.getHours().toString().padStart(2, "0");
      var mm = dt.getMinutes().toString().padStart(2, "0");
      var ss = dt.getSeconds().toString().padStart(2, "0");
      return `${y}-${m}-${d}`;
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-form-item {
    input {
      text-align: left;
    }
  }
}
.open-right {
  ::v-deep {
    .el-form-item {
      margin-bottom: 0;
    }
  }
}
</style>
